﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SklepISI.Core.Interfaces;
using SklepISI.Core.Models;
using SklepISI.Web.Models;

namespace SklepISI.Web.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/

        private IProductRepository _productRepository;
        public ProductController(IProductRepository productRepository)
        {
            _productRepository = productRepository;
        }

        public ActionResult List(int categoryId)
        {
            ProductsViewModel model = new ProductsViewModel();

            var products = categoryId > 0
                               ? _productRepository.GetProducts(categoryId)
                               : _productRepository.GetProducts();


            model.Products = products;

            return View(model);
        }

        public ActionResult Details(int productId)
        {
            var product = _productRepository.GetProducts().Where(x => x.ProductId == productId).FirstOrDefault();
            return View(product);
        }
    }
}
